package com.gt.web.srv.interceptors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private CommonInterceptor commonInterceptor;

    @Value("${web.upload-path}")
    private String showPath;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(commonInterceptor).addPathPatterns("/**")
                //登录 注册
                .excludePathPatterns("/api/user/login", "/api/app/loginByApp")
                .excludePathPatterns("/api/ad/**", "/api/community/**")
                // 忽略swagger
                .excludePathPatterns("/webjars/**","/doc.html/**","/v3/api-docs/**","/v2/api-docs/**","/swagger/**","/swagger-ui/**","/swagger-resources/**","/swagger-resources**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:" + showPath);
    }
}
